<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "header_info".
 *
 * @property integer $id
 * @property integer $uid
 * @property string $device_id
 * @property integer $app_id
 * @property string $app_build_code
 * @property string $app_version
 * @property string $deviceInfo
 * @property string $channel
 * @property string $product
 * @property integer $create_time
 * @property integer $type
 */
class HeaderInfo extends \yii\db\ActiveRecord
{
    const APP_IOS = 1;//内部应用ID;1.IOS;2.android;
    const APP_ANDROID = 2;//内部应用ID;1.IOS;2.android;
    const TYPE_REGISTER = 1;//类型;1.注册
    const TYPE_LOGIN = 2;//类型;2.登录

    public static $appPlatformArray = array(
        self::APP_IOS => 'IOS',
        self::APP_ANDROID => 'ANDROID',
    );
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'header_info';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'app_id', 'create_time','type'], 'integer'],
            [['device_id', 'deviceInfo'], 'string', 'max' => 256],
            [['app_build_code', 'app_version', 'channel', 'product'], 'string', 'max' => 32],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'uid' => '用户ID',
            'device_id' => '设备ID',
            'app_id' => '内部应用ID;1.IOS;2.android;',
            'app_build_code' => '创建编号',
            'app_version' => '软件版本',
            'deviceInfo' => '品牌－软硬件信息',
            'channel' => '渠道名',
            'product' => '产品名称',
            'create_time' => '创建时间',
            'type' => '类型;1.注册;2.登录',
        ];
    }

    public function save($runValidation = true, $attributeNames = null)
    {
        if($this->isNewRecord) {
            $this->create_time=time();
        }
        return parent::save($runValidation, $attributeNames);
    }
}
